#!/bin/bash
BASE_DIR=`cd $(dirname $0);pwd`
#set -x
#脚本需要放在可以连接世界网络和国内网络的服务器上使用,下载Github上的包并上传至国内Nginx下载服务器
DEST_IP=39.98.69.131
SFTP_USER=user1

fouction_download(){
	read -p "请输入软件地址:" URL
	wget ${URL} && echo "下载成功" || exit 404
	PACKAGE_NAME=`echo ${URL} |awk -F '/' '{print $NF}'`
}

fouction_uplaod(){

read -p "请输入软件上传目标目录,如果是版本号命名目录不用写字母v:" SFTP_DIR

sftp ${SFTP_USER}@${DEST_IP}<<EOF
cd ${SFTP_DIR}
put ${PACKAGE_NAME}
quit
EOF

rm -rf ${PACKAGE_NAME}
echo "新的软件地址为 https://download.stsay.com/user1/${SFTP_DIR}/${PACKAGE_NAME}"

}
fouction_download
fouction_uplaod
